<?php

class Admin_PropertyController extends My_Controller_ActionAdmin {

    public function indexAction() {
        $daoProperty = new Application_Model_DAO_Property();
        $list = $daoProperty->getAll();
        $this->view->list = $list;
    }

    public function saveAction() {
        $pid = $this->_getParam('id');
        $daoProperty = new Application_Model_DAO_Property();
        $property = $daoProperty->get($pid);
        if (empty($property)) {
            $this->addError($this->translate('XXX_ADMIN_PROPERTY_NOT_EXISTS'));
            $url = $this->url(array('controller' => 'property'));
            $this->_redirect($url);
        }
        $form = new Admin_Form_Property_Edit($property);

        if (!$this->_request->isPost()) {
            $form->populate($property);
        }

        if (!$this->_request->isPost() || !$form->isValid($_POST)) {
            $this->view->form = $form;
            $this->renderForm();
            return;
        }
        $data = $form->getValues();

        $daoProperty->save($property['name'], $data['value']);

        $url = $this->url(array('controller' => 'property'));
        $this->_redirect($url);
    }

}

